<?
	include_once('global.php');
	if(isset($_GET['refer']))
	{
		$refer = $_SESSION['refer'] = $_GET['refer'];
	}elseif(isset($_SESSION['refer']))
	{
		$refer = $_SESSION['refer'];
	}else{
		$refer = $_SESSION['refer'] = $_SERVER['HTTP_REFERER'];
	}
	if($refer == null || $refer == '') $refer = 'index.php';
	
	if(isset($_REQUEST['Email']))
	{
		if($ValidationErrors = Login($_REQUEST['Email'], $_REQUEST['Password']))
		{
			$rs = $_REQUEST;
		}else{
			echo "refer: $refer";
			header("location: $refer");
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Please Login</title>
<link rel="stylesheet" type="text/css" href="forms.css"/>
</head>

<body>

	<ul class="error">
    	<? foreach($ValidationErrors as $key => $value) { ?>
        	<li><?=$key?>: <?=$value?> </li>
        <? } ?>
    </ul>
	<form method="post">
        <div>
            <label for="Email">Email:</label>
            <input
            	class="<?=isset($ValidationErrors['Email']) ? 'iError' : ''?>"
            	type="text" name="Email"
            	value="<?=$rs['Email']?>" id="Email" />
            <? if(isset($ValidationErrors['Email'])) { ?><?=$ValidationErrors['Email']?><? } ?>
        </div>
        <div>
            <label for="Password">Password:</label>
            <input
            	class="<?=isset($ValidationErrors['Password']) ? 'iError' : ''?>"
            	type="password" name="Password"
            	value="<?=$rs['Password']?>" id="Password" />
            <? if(isset($ValidationErrors['Password'])) { ?><?=$ValidationErrors['Password']?><? } ?>
        </div>
        <input type="submit" value="Login" />
        <a href="lost.php">Forgot your password</a>
        <a href="createaccount.php">Create an account</a>
    </form>


</body>
</html>